//
//  VoiceReadHeaderView.m
//  ShowYork
//
//  Created by hxh on 2021/4/19.
//  Copyright © 2021 hxh. All rights reserved.
//

#import "VoiceReadHeaderView.h"

@interface VoiceReadHeaderView ()
@property (nonatomic,strong)UIImageView *headIcon;
@property (nonatomic,strong)UILabel *titleLb;
@property (nonatomic,strong)UILabel *voiceCountLb;
@property (nonatomic,strong)UILabel *listenCountLb;
@property (nonatomic,strong)UILabel *descLb;
@property (nonatomic,strong)UIView *line;

@end

@implementation VoiceReadHeaderView



- (instancetype)init
{
    self = [super init];
    if (self) {
        [self setUI];
    }
    return self;
}
- (void)setUI{
    
    CGSize size = [RPAppManager getTextSizeWithText:[NSString stringWithFormat:@"简介：%@",self.itemModel.introduce] font:font(12) maxSize:CGSizeMake(kScreenW - 32, MAXFLOAT)];
  
    CGFloat height  = kNavBarHeight + 20 * 2 + 21 + 80 + ceil(size.height) + 16;
    
    self.backgroundColor = RGBA(201, 197, 195, 1);
    
    self.frame = CGRectMake(0, 0, kScreenW, height);
  
    self.headIcon = [[UIImageView alloc]init];
    self.headIcon.backgroundColor = RGBA(240, 240, 240, 1);
    self.headIcon.layer.cornerRadius = 8;
    self.headIcon.layer.masksToBounds = YES;
    [self addSubview:self.headIcon];
    
    self.titleLb = [[UILabel alloc]init];
    self.titleLb.textColor = [UIColor whiteColor];
    self.titleLb.font = [UIFont boldSystemFontOfSize:18];
    self.titleLb.text = @"-";
    [self addSubview:self.titleLb];
    
    self.voiceCountLb = [[UILabel alloc]init];
    self.voiceCountLb.textColor = [UIColor whiteColor];
    self.voiceCountLb.text = @"声音：-";
    self.voiceCountLb.font = font(12);
    [self addSubview:self.voiceCountLb];
    
    self.listenCountLb = [[UILabel alloc]init];
    self.listenCountLb.textColor = [UIColor whiteColor];
    self.listenCountLb.text = @"收听量：-";
    self.listenCountLb.font = font(12);
    [self addSubview:self.listenCountLb];
    
    self.line = [[UIView alloc]init];
    self.line.backgroundColor = [UIColor whiteColor];
    [self addSubview:self.line];
    
    self.descLb = [[UILabel alloc]init];
    self.descLb.text = @"-";
    self.descLb.textColor = [UIColor whiteColor];
    self.descLb.font = font(12);
    self.descLb.numberOfLines = 0;
    [self addSubview:self.descLb];
    
    [self.headIcon mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self).offset(16);
        make.top.equalTo(self).offset(kNavBarHeight + 20);
        make.size.mas_equalTo(CGSizeMake(88, 88));
    }];
    
    [self.titleLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.headIcon.mas_right).offset(16);
        make.top.equalTo(self.headIcon.mas_top).offset(8);
    }];
    [self.voiceCountLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.titleLb);
        make.top.equalTo(self.titleLb.mas_bottom).offset(20);
    }];
    [self.line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(1);
        make.height.mas_equalTo(8);
        make.centerY.equalTo(self.voiceCountLb);
        make.left.equalTo(self.voiceCountLb.mas_right).offset(16);
    }];
    [self.listenCountLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.line.mas_right).offset(16);
        make.centerY.equalTo(self.voiceCountLb);
    }];
//
    [self.descLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.headIcon);
        make.right.equalTo(self).offset(-16);
        make.top.equalTo(self.headIcon.mas_bottom).offset(20);
    }];
}
- (void)setItemModel:(VoiceReadTotalItemModel *)itemModel{
    _itemModel = itemModel;
    [self.headIcon sd_setImageWithURL:[NSURL URLWithString:itemModel.coverLog]];
    self.titleLb.text = itemModel.title;
    self.descLb.text = [NSString stringWithFormat:@"简介：%@",itemModel.introduce];
    
    NSString *voiceTitle = @"";
    int count = itemModel.voiceNum.intValue;
    if (itemModel.voiceNum.intValue >= 10000) {
        if (count % 1000 == 0) {
            count += 1;
        }
        voiceTitle = [NSString stringWithFormat:@"声音：%@w个",[RPAppManager notRounding:count/10000.0f afterPoint:1]];
    }else{
        voiceTitle = [NSString stringWithFormat:@"声音：%i个",count];
    }
    
    self.voiceCountLb.text = voiceTitle;
    
    NSString *listenTitle = @"";
    int listenCount = itemModel.listenNum.intValue;
    if (itemModel.listenNum.intValue >= 10000) {
        if (listenCount % 1000 == 0) {
            listenCount += 1;
        }
        listenTitle = [NSString stringWithFormat:@"收听量：%@w",[RPAppManager notRounding:listenCount/10000.0f afterPoint:1]];
    }else{
        listenTitle = [NSString stringWithFormat:@"收听量：%i",listenCount];
    }
    self.listenCountLb.text = listenTitle;
    
    
    
    
}

@end
